﻿using System.Collections.Generic;
using System.Linq;
using CID.Domain.Operations;
using CID.Web.Controllers;
using NailsFramework.IoC;
using NailsFramework.Persistence;
using NailsFramework.UserInterface.TestingSupport;
using NUnit.Framework;

namespace CID.Web.Tests.Controllers
{
    [TestFixture]
    class EnvironmentStateControllerTests : BaseWebTests
    {
        [Inject]
        public IBag<Environment> Environments { private get; set; }
        private EnvironmentStateController controller;

        public override void SetUp()
        {
            base.SetUp();
            controller = TestControllers.Get<EnvironmentStateController>();
        }


        [Test]
        public void TestIndex_ShouldGetAllEnabledEnvironmentsAndReturnDefaultView()
        {
            var result = controller.Index();

            Assert.IsNotNull(result);
            Assert.AreEqual("", result.ViewName);
            Assert.IsInstanceOf<IEnumerable<Environment>>(result.Model);
            var outputEnvironments = ((IEnumerable<Environment>)result.Model).ToArray();
            CollectionAssert.IsSubsetOf(outputEnvironments, Environments);
            CollectionAssert.IsEmpty(outputEnvironments.Where(x => !x.Enabled));
        }


        [Test]
        public void TestEnvironmentStateDetails_ShouldReturnDefaultViewWithEntity()
        {
            var model = Environments.First();

            var result = controller.EnvironmentStateDetails(model.Id);

            Assert.IsNotNull(result);
            Assert.AreEqual("", result.ViewName);
            Assert.IsInstanceOf<Environment>(result.Model);
            Assert.AreEqual(model.Id, ((Environment)result.Model).Id);
        }
    }
}
